package com.yj.springbootrabbitmq.rest;

import com.yj.springbootrabbitmq.pojo.User;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class TestController {


    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("send")
    public String send(){
        List<User>list =  new ArrayList<>();

        User user1 = new User();
        user1.setId(1);
        user1.setName("zs");
        user1.setAddress("湖南长沙");
        User user2 = new User();
        user2.setId(2);
        user2.setName("ls");
        user2.setAddress("湖南永州");
        User user3 = new User();
        user3.setId(3);
        user3.setName("ww");
        user3.setAddress("湖南岳阳");


        list.add(user1);
        list.add(user2);
        list.add(user3);
        CorrelationData correlationData = new CorrelationData();
        correlationData.setId("test");
        rabbitTemplate.convertAndSend("test",list,correlationData);

        return "send success";
    }

}
